package com.atguigui.leetcode1;

/**
 * 2299.强密码检验器 II
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/1/19 8:42
 */
public class P2299StrongPasswordCheckerIi {
    public static void main(String[] args) {
        Solution solution = new P2299StrongPasswordCheckerIi().new Solution();

        System.out.println(solution.strongPasswordCheckerII("z1A!A!A!"));
        // TO TEST
    }

    class Solution {
        public boolean strongPasswordCheckerII(String password) {

            if (password.length() < 8) {
                return false;
            }

            char[] c = {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+'};

            boolean s = false;
            boolean b = false;
            boolean n = false;
            boolean sp = false;
            char old = ' ';
            for (int i = 0; i < password.length(); i++) {

                char word = password.charAt(i);
                if (!s && word >= 97 && word <= 122) {
                    s = true;
                }
                if (!b && word >= 65 && word <= 90) {
                    b = true;
                }
                if (!n && Character.isDigit(word)) {
                    n = true;
                }
                if (old == word) {
                    return false;
                } else {
                    old = word;
                }

                if (!sp) {
                    for (int j = 0; j < c.length; j++) {
                        if (c[j] == word) {
                            sp = true;
                        }
                    }
                }

            }

            return s && b && n && sp == true ? true : false;
        }
    }
}
